//package development.game;
//
//import state.util.Hashtable;
//import java.util.Vector;
//
//import state.Graphics;
//
//import state.GameConstants;
//import state.GameForm;
//import state.Key;
//import state.TimerListener;
//import state.component.TextField;
//import state.font.FontManager;
//import state.font.ImageFont;
//import state.font.ImageText;
//import state.socket.DataPackage;
//import state.socket.DataReceiveListener;
//import state.util.Color;
//import development.Constants;
//import development.Global;
//import development.bean.Game;
//import development.bean.Question;
//import development.bean.User;
//
//public class FrmDuoiHinhBatChu extends GameForm implements DataReceiveListener, TimerListener {
//  private ImageText text;
//  private final int READY_IN_GAME_REQUEST = 3001;
//  private final int SEND_QUESTION = 3002;
//  private final int SELECT_TO_ANSWER = 3003;
//  private final int SEND_RESULT_AFTER_ANSWER = 3004;
//  private final int KHONG_TRA_LOI = 3005;
//  private final int FINISHED_QUESTION = 3006;
//  private static GameForm singleton;
//  private String [] str;
//  private int STATE_SCREEN;
//  public Vector tableUsers;
//  private int numberOfPlayer;
//  Question question;
//  int timePerQuestion;
//  int count;
//  int[] score = {100, 200, 500, 1000, 2000, 5000, 8000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000};
//  int[] obtainScores;
//  private int currentQuestionIndex;
//  private String answerString;
//  private boolean isAnswered;
//  private boolean isBuffer;
//  private TextField answerTextField;
//  
//  public static GameForm instance() {
//    if (singleton == null) {
//      singleton = new FrmAiLaTrieuPhu();
//    }
//    return singleton;
//  }
//  
//  public void init(java.util.Hashtable parameters) {
//	  isAnswered = false;
//	  answerString = "";
//	  tableUsers = new Vector();
//	tableUsers = Global.tableUsers;
//	timePerQuestion = 0;
//	numberOfPlayer = tableUsers.size();
//	obtainScores = new int[numberOfPlayer];
//    text = FontManager.getFont(FontManager.FONT_SIZE_11);
//    STATE_SCREEN = 0;
//    answerTextField  = new TextField(TextField.CONSTRAINT_USER_NAME, Constants.TEXT_FIELD_STYLE);
//    int timeReady = System.currentTimeMillis();
////    DataPackage dataPackage = Game.createGamePackage(READY_IN_GAME_REQUEST);
////    dataPackage.putLong(timeReady);
////    Global.gameActionClient.write(dataPackage);
//    sendMessageAction(READY_IN_GAME_REQUEST, "");
//  };
//  
//  public void draw(Graphics g) {
////    text.drawString(g, "This form is not implement yet", GameConstants.SCREEN_WIDTH / 2, GameConstants.SCREEN_HEIGHT / 2, GameConstants.CENTER_ANCHOR);
//	  g.setColor(Color.BLACK_CODE);
//	  g.fillRect(0, 0, GameConstants.SCREEN_WIDTH, GameConstants.SCREEN_HEIGHT);
//	  for (int i = 0; i < numberOfPlayer; i ++) {
//		  drawUserInfo(g, ((User)tableUsers.elementAt(i)).getName(), 5, 5 + i *60);
//	  }
//	  if (STATE_SCREEN == 2) {
//		  drawQuestion(g);
//	  } else {
//		  drawLevel(g);
//	  }
//	  
//  }
//  public void drawQuestion(Graphics g) {
//	  if (question != null) {
////		  text.drawString(g, question.getContent(),Color.WHITE_CODE, 160, 20, GameConstants.CENTER_ANCHOR);  
//		  text.drawParagraph(g, question.getContent(), Color.WHITE_CODE, 120, 0, 100, 20);
//		  text.drawString(g, question.getResult1(), Color.WHITE_CODE, 160, 100, GameConstants.TOP_LEFT_ANCHOR);
//		  text.drawString(g, question.getResult2(), Color.WHITE_CODE, 160, 120, GameConstants.TOP_LEFT_ANCHOR);
//		  text.drawString(g, question.getResult3(), Color.WHITE_CODE, 160, 140, GameConstants.TOP_LEFT_ANCHOR);
//		  text.drawString(g, question.getResult4(), Color.WHITE_CODE, 160, 160, GameConstants.TOP_LEFT_ANCHOR);
//		  g.setColor(Color.BLUE_CODE);
////		  g.drawRect(160, 100 + selectedIndexAnswer *20, text.stringWidth(question.getResult1()), 10);
//	  }
//  }
//  public void drawUserInfo(Graphics g, String username, int x, int y) {
//	    ImageFont text8 = FontManager.getFont(FontManager.FONT_SIZE_8);
////	    int anchor = isRightToLeft ? GameConstants.TOP_RIGHT_ANCHOR : GameConstants.TOP_LEFT_ANCHOR;
//	    g.drawImage(Global.getAvatar(username), x, y, GameConstants.TOP_LEFT_ANCHOR);
//
//	    text8.drawString(g, username, Color.WHITE_CODE, x, y + 35, GameConstants.TOP_LEFT_ANCHOR);
////	    if (username.equals(Global.currentUser.getName())) {
//	      text8.drawString(g, "Điểm: " + obtainScores[getUserIndex(username)], Color.YELLOW_CODE, x, y + 45, GameConstants.TOP_LEFT_ANCHOR);
//	      g.setColor(Color.YELLOW_CODE);
////	    }
//	  }
//  public void drawLevel(Graphics g) {
//	  for (int i = 0; i < 15; i ++) {
//		  text.drawString(g, String.valueOf(score[i]), Color.WHITE_CODE, 160, 20 + i*12, GameConstants.TOP_LEFT_ANCHOR);
//	  }
//	  g.fillRect(160, 20 + 20 * currentQuestionIndex, 60, 20);
//  }
//  public void keyReleased(int keyCode) {
//    if (keyCode == Key.SOFT_RIGHT) {
//      Global.nextState(Global.systemCanvas.lastState, null);
//    }
//    switch (keyCode) {
//	case Key.RIGHT:
//		
//		break;
//	case Key.LEFT:
//		
//		break;
//		
//	case Key.DOWN:
//		break;
//	case Key.UP:
//		break;
//	case Key.FIRE:
//		if (answerString.length() >0 && !isAnswered) {
//			isAnswered = true;
//			sendMessageAction(SELECT_TO_ANSWER, answerString, timePerQuestion);
//		}
//		break;
//	default:
//		break;
//	}
//  }
//
//  public void onConnectDone() {
//  }
//
//  public void onConnectFail() {
//  }
//
//  public void onDisconnect() {
//  }
//
//  private String[] split(String original,String separator) {
//	    String[] nodes = new String[5];
//	    // Parse nodes into vector
//	    int index = original.indexOf(separator);
//	    int dem = 0;
//	    while(index >= 0) {
//	    	if (dem < 5) {
//	    		nodes[dem] = original.substring(0, index);
//		        original = original.substring(index+separator.length());
//		        index = original.indexOf(separator);
//		        dem ++;
//	    	}
//	    	
//	    }
//	    // Get the last node
//	    if (dem < 5) {
//	    	 nodes[dem] = original;
//	    }
//	   return nodes;
//	}
//  
//  public void onRecieveData(DataPackage dataPackage) {
//	 
//	  int header = dataPackage.getHeader();
//	    switch (header) {
//	    case SEND_QUESTION:
//	    	isAnswered = false;
//	    	STATE_SCREEN = 2;
//	    	question = new Question();
//	    	currentQuestionIndex = dataPackage.nextInt();
//	    	String s = dataPackage.nextString();
//	    	String[] data = split(s, "|");
//	    	question.setContent(data[0]);
//	    	question.setResult1(data[1]);
//	    	question.setResult2(data[2]);
//	    	question.setResult3(data[3]);
//	    	question.setResult4(data[4]);
//	    	timePerQuestion = 0;
//	    	break;
//	    case SEND_RESULT_AFTER_ANSWER:
////	    	pk.putInt(currentQuestionIndex); // chuyen sang cau hoi cao hon
////    		pk.putString(user.getUsername()); // username nguoi tra loi dung
////    		pk.putInt(score[currentQuestion.getIndex()]); // so diem nguoi tra loi dung
//    		
//    		currentQuestionIndex = dataPackage.nextInt();
//    		String user = dataPackage.nextString();
//    		int sc = dataPackage.nextInt();
//    		obtainScores[getUserIndex(user)] +=  sc;
//    		isBuffer = true;
//    		STATE_SCREEN = 2;
//	    	break;
//	    case FINISHED_QUESTION:
//	    	STATE_SCREEN = 1;
//	    	break;
//	    }
//	    
//  }
//  
//  private int getUserIndex(String username) {
//	  int index;
//	  for (int i = 0; i < numberOfPlayer; i ++) {
//		  User us = (User)tableUsers.elementAt(i);
//		  if (username.equals(us.getName())) {
//			  index = i;
//			 return index;
//		  }
//	  }
//	  return 0;
//  }
//  
//  private void sendMessageAction(int header, String data) {
//	    DataPackage dataPackage = Game.createGamePackage(header);
//	    dataPackage.putString(data);
//	    Global.gameActionClient.write(dataPackage);
//	  }
//  
//  private void sendMessageAction(int header, String data, int time) {
//	    DataPackage dataPackage = Game.createGamePackage(header);
//	    dataPackage.putString(data);
//	    Global.gameActionClient.write(dataPackage);
//	  }
//
//public void doTask() {
//	count = (count + 1) %2000;
//	if (count % 10 == 0) {
//		if (timePerQuestion < 15) {
//			timePerQuestion +=1;
//		}
//		if (timePerQuestion>=15 && (isAnswered == false)) {
//			sendMessageAction(KHONG_TRA_LOI, "");
//		} 
//	}
//}
//}
